<template>
  <div class="step-progress">
    <!--步骤条-->
    <div class="step-container">
      <!-- <div
        class="step-item"
        v-for="(item, index) in stepConfig"
        :key="index"
        :class="{ active: current === index }"
      >
        <div class="text">{{ item.title }}</div>
        <div class="step-icon step-left" v-if="index !== 0"></div>
        <div
          class="step-icon step-right"
          v-if="index !== stepConfig.length - 1"
        ></div>
      </div> -->
      <a-steps :current="current">
        <a-step
          v-for="(item, index) in stepConfig"
          :key="index"
          :title="item.title"
        />
      </a-steps>
    </div>
    <!--主体-->
    <div class="step-body">
      <add-active
        v-if="current === 0"
        ref="addActive"
        :formData="formData"
        :readOnly="readOnly"
        :passModify="passModify"
        :passwordInfo="passwordInfo"
      ></add-active>
      <prize-setting
        v-if="current === 1"
        :formData="formData"
        :readOnly="readOnly"
        :passModify="passModify"
      ></prize-setting>
      <page-style
        v-if="current === 2"
        :formData="formData"
        :readOnly="readOnly"
      ></page-style>
    </div>
    <!--按钮-->
    <div class="steps-action">
      <a-button class="btn" @click="handelBack">取消</a-button>
      <a-button class="btn" v-if="current > 0" @click="handelPrev"
        >上一步</a-button
      >
      <a-button
        class="btn"
        v-if="current < stepConfig.length - 1"
        type="primary"
        @click="handelNext"
        >下一步</a-button
      >
      <a-button
        class="btn"
        v-if="current === stepConfig.length - 1 && !readOnly"
        type="primary"
        @click="handelCommit"
      >
        确定
      </a-button>
    </div>
  </div>
</template>

<script>
import addActive from "@views/menuPage/marketing/lottery/components/creatActive/index.vue";
import prizeSetting from "@views/menuPage/marketing/lottery/components/prizeSetting/index.vue";
import pageStyle from "@views/menuPage/marketing/lottery/components/pageStyle/index.vue";
export default {
  name: "creatActive",
  components: {
    addActive,
    prizeSetting,
    pageStyle,
  },
  data() {
    return {
      formData: {
        activeName: "",
        activeTime: "",
        startDate: "",
        endDate: "",
        participant: "0",
        benefitsCardIdList: [],
        labelIdList: [],
        goodsIdList: [],
        activeType: "1",
        unlimited: "1",
        limitedNum: 1,
        conditionalLottery: [],
        conditionalData: {
          integralNum: 1,
          exchangeNum: 1,
          freeNum: 1,
          priceNum: 1,
          orderNum: 1,
          shareNum: 1,
          friendsNum: 1,
          freeLotteryNum: 1,
          buyNum: 1,
          cashNum: 1,
          cashCount: 1,
          product: "1",
          exchangeCount: 1,
          sharelimitNum: 1,
          limitfriendsNum: 1,
          limitBuyNum: 1,
          singleNum: 1,
          singleMoney: 1,
          singleLimitNum: 1,
          increaseNum: 1,
          increaseMoney: 1,
          increaseLimitNum: 1,
        },
        //奖品设置
        tableData: [],
        probabilitySetting: "1",
        isAudit: "0",
        validDuration: 1,
        peopleCount: 100,
        sendPoints: 0,
        notWinning: false,
        giftRules: "",
        //装修
        pageJson: {
          styleType: 1, // 1系统样式  2自定义
          shareBtnshow: 1, // 分享按钮1 展示   0隐藏
          shareBtnText: "告诉好友", // 分享按钮文案
          goShopBtnShow: 1, //进入店铺 1 展示   0隐藏
          goShopBtnText: "进入店铺", // 进入店铺按钮文案
          activetyName: "惊喜拆盲盒", //活动名称
          activetyDesc: "奖品多 价值高 拆盲盒 更惊喜", //活动描述
          residueNum: 1, //剩余次数 1 展示   0隐藏
          BoxNum: 6, //盲盒数量 4：4盒   6：6盒   9： 9盒
          boxList: [
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
            "拆神秘盲盒",
          ], //盲盒文案
          giftPoolShow: 1, //奖品池 1展示 0 隐藏
          giftPoolName: "奖品池", //奖品池名称
          myPrizeShow: 1, //我的奖品 1展示 0 隐藏
          myPrizeName: "我的奖品", //我的奖品名称
          myPrizeBtnShow: 1, //我的奖品按钮 1展示 0 隐藏
          myPrizeBtnName: "已发放，查看", //我的奖品按钮 1展示 0 隐藏
          activetyRuleShow: 1, //活动规则 1展示 0 隐藏
          activetyRuleText: "活动规则", // 活动规则名称
          activetyRuleDesc: "欢迎参加抽奖活动，如有任何问题可联系官方客服！", //活动规则描述
          drawBtnShow: 1, //悬浮获取抽奖按钮 1展示 0 隐藏
          drawBtnText: "获取抽奖机会", // 悬浮获取抽奖按钮名称

          //自定义
          bannerImageUrl: "", //背景图
          bannerType: 1, //1系统样式 2自定义

          //分享按
          shareImageUrl: "", //分享按钮图片
          sharebtnType: 1, //分享按钮1系统样式 2自定义
          shareBtnColor: "#ffffff", //分享按钮字体颜色
          sharefontSize: 8, //分享按钮字体颜色
          sharefontWeight: "bold", //分享按钮字体粗细

          //进入店铺
          goShopImageUrl: "", //进入店铺按钮图片
          goShopbtnType: 1, //进入店铺按钮1系统样式 2自定义
          goShopBtnColor: "#ffffff", //进入店铺按钮字体颜色
          goShopfontSize: 8, //进入店铺按钮字体颜色
          goShopfontWeight: "bold", //进入店铺按钮字体粗细

          //活动名称
          activetyNameColor: "#ffffff", //活动名称字体颜色
          activetyNamefontSize: 40, //活动名称字体大小
          activetyNamefontWeight: "bold", //活动名称字体粗细

          //活动描述
          activetyDescColor: "#ffffff", //活动描述字体颜色
          activetyDescfontSize: 14, //活动描述字体大小
          activetyDescfontWeight: "bold", //活动描述字体粗细
          activetyDescBordercolor: "#cfa56d", //活动描述底框颜色
          activetyDescAngelType: "1", //活动描述底框倒角 0直角 1倒角

          //剩余次数
          residueNumColor: "#bfbfbf", //剩余次数字体颜色
          residueNumfontSize: 12, //剩余次数字体大小
          residueNumfontWeight: "normal", //剩余次数字体粗细
          residueNumBordercolor: "#383838", //剩余次数底框颜色
          residueNumAngelType: "0", //剩余次数底框倒角 0直角 1倒角

          //盲盒自定义
          BoxImgUrl: "", //盲盒自定义图片
          BoxStyleType: 1, //盲盒自定义类型1系统样式 2自定义
          BoxColor: "#ffffff", //盲盒自定义字体颜色
          BoxfontSize: 14, //盲盒自定义字体大小
          BoxfontWeight: "bold", //盲盒自定义字体粗细
          BoxBordercolor: "#383767", //盲盒自定义底框颜色
          BoxAngelType: "1", //盲盒自定义底框倒角 0直角 1倒角

          //奖品池
          giftPoolColor: "#ffffff", //奖品池字体颜色
          giftPoolfontSize: 16, //奖品池字体大小
          giftPoolfontWeight: "bold", //奖品池字体粗细
          poolTitleColor: "#c0a27b", //标题底框颜色
          poolAngelType: "1", //奖品池底框倒角 0直角 1倒角
          poolTextColor: "#3d3d4e", //奖品池内容底框颜色
          pooltextAngelType: "1", //奖品池内容底框倒角 0直角 1倒角

          //中奖轮播
          prizeCarousel: 1, //中奖轮播 1展示 0隐藏
          prizeColor: "#ffffff", //中奖轮播字体颜色
          prizefontSize: 14, //中奖轮播字体大小
          prizefontWeight: "bold", //中奖轮播字体粗细
          prizeBordercolor: "#c8505c", //中奖轮播底框颜色
          prizeAngelType: "1", //中奖轮播底框倒角 0直角 1倒角

          //我的奖品
          awardColor: "#ffffff", //我的奖品字体颜色
          awardfontSize: 16, //我的奖品字体大小
          awardfontWeight: "bold", //我的奖品字体粗细
          awardTitleColor: "#c0a27b", //我的奖品标题底框颜色
          awardAngelType: "1", //我的奖品底框倒角 0直角 1倒角
          awardTextColor: "#3d3d4e", //我的奖品内容底框颜色
          awardTextAngelType: "1", //奖品池内容底框倒角 0直角 1倒角

          //我的奖品按钮
          awardBtnColor: "#ffffff", //我的奖品按钮字体颜色
          awardfontBtnSize: 14, //我的奖品按钮字体大小
          awardfontBtnWeight: "bold", //我的奖品按钮字体粗细
          awardTitleBtnColor: "#676596", //我的奖品按钮底框颜色
          awardAngelBtnType: "1", //我的奖品按钮底框倒角 0直角 1倒角

          //活动规则标题
          ruleTitleColor: "#ffffff", //活动规则标题字体颜色
          ruleTitlefontSize: 16, //活动规则标题字体大小
          ruleTitlefontWeight: "bold", //活动规则标题字体粗细
          ruleTitlebgColor: "#c0a27b", //活动规则标题底框颜色
          ruleTitleAngelType: "1", //活动规则标题底框倒角 0直角 1倒角

          //活动规则内容
          ruleTextColor: "#ffffff", //活动规则内容字体颜色
          ruleTextfontSize: 12, //活动规则内容字体大小
          ruleTextfontWeight: "bold", //活动规则内容字体粗细
          ruleTextbgColor: "#3d3d4e", //活动规则内容标题底框颜色
          ruleTextAngelType: "1", //活动规则内容底框倒角 0直角 1倒角

          drawtColor: "#ffffff", //悬浮获取抽奖按钮字体颜色
          drawfontSize: 16, //悬浮获取抽奖按钮字体大小
          drawfontWeight: "bold", //悬浮获取抽奖按钮字体粗细
          drawbgColor: "#c8505c", //悬浮获取抽奖按钮标题底框颜色
          drawAngelType: "1", //悬浮获取抽奖按钮底框倒角 0直角 1倒角

          //高级设置
          //中奖实物效果弹窗
          winningPrizeType: 1, //中奖实物效果类型1系统样式 2自定义
          winningPrizeImgUrl: "", //中奖实物效果地址
          winningPrizeColor: "#ffffff",
          //未中奖效果弹窗
          noWinningType: 1, //未中奖实物效果类型1系统样式 2自定义
          noWinningImgUrl: "", //中奖实物效果地址
          //积分展示图
          integralType: 1, //积分展示图效果类型1系统样式 2自定义
          integralImgUrl: "", //积分展示图地址
          integralColor: "#ffffff",
          //优惠券展示图
          couponType: 1, //积分展示图效果类型1系统样式 2自定义
          couponImgUrl: "", //优惠券展示图地址
          couponColor: "#ffffff",
          //分享样式海报图
          posterType: 1, //海报图类型1系统样式 2自定义
          posterImgUrl: "", //海报图地址
          posterText: "惊喜盲盒快来猜，数量有限先到先得", //分享海报文案
        },
      },
      pageJson: {
        styleType: 1, // 1系统样式  2自定义
        shareBtnshow: 1, // 分享按钮1 展示   0隐藏
        shareBtnText: "告诉好友", // 分享按钮文案
        goShopBtnShow: 1, //进入店铺 1 展示   0隐藏
        goShopBtnText: "进入店铺", // 进入店铺按钮文案
        activetyName: "惊喜拆盲盒", //活动名称
        activetyDesc: "奖品多 价值高 拆盲盒 更惊喜", //活动描述
        residueNum: 1, //剩余次数 1 展示   0隐藏
        BoxNum: 6, //盲盒数量 4：4盒   6：6盒   9： 9盒
        boxList: [
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
          "拆神秘盲盒",
        ], //盲盒文案
        giftPoolShow: 1, //奖品池 1展示 0 隐藏
        giftPoolName: "奖品池", //奖品池名称
        myPrizeShow: 1, //我的奖品 1展示 0 隐藏
        myPrizeName: "我的奖品", //我的奖品名称
        myPrizeBtnShow: 1, //我的奖品按钮 1展示 0 隐藏
        myPrizeBtnName: "已发放，查看", //我的奖品按钮 1展示 0 隐藏
        activetyRuleShow: 1, //活动规则 1展示 0 隐藏
        activetyRuleText: "活动规则", // 活动规则名称
        activetyRuleDesc: "欢迎参加抽奖活动，如有任何问题可联系官方客服！", //活动规则描述
        drawBtnShow: 1, //悬浮获取抽奖按钮 1展示 0 隐藏
        drawBtnText: "获取抽奖机会", // 悬浮获取抽奖按钮名称

        //自定义
        bannerImageUrl: "", //背景图
        bannerType: 1, //1系统样式 2自定义

        //分享按
        shareImageUrl: "", //分享按钮图片
        sharebtnType: 1, //分享按钮1系统样式 2自定义
        shareBtnColor: "#ffffff", //分享按钮字体颜色
        sharefontSize: 8, //分享按钮字体颜色
        sharefontWeight: "bold", //分享按钮字体粗细

        //进入店铺
        goShopImageUrl: "", //进入店铺按钮图片
        goShopbtnType: 1, //进入店铺按钮1系统样式 2自定义
        goShopBtnColor: "#ffffff", //进入店铺按钮字体颜色
        goShopfontSize: 8, //进入店铺按钮字体颜色
        goShopfontWeight: "bold", //进入店铺按钮字体粗细

        //活动名称
        activetyNameColor: "#ffffff", //活动名称字体颜色
        activetyNamefontSize: 40, //活动名称字体大小
        activetyNamefontWeight: "bold", //活动名称字体粗细

        //活动描述
        activetyDescColor: "#ffffff", //活动描述字体颜色
        activetyDescfontSize: 14, //活动描述字体大小
        activetyDescfontWeight: "bold", //活动描述字体粗细
        activetyDescBordercolor: "#cfa56d", //活动描述底框颜色
        activetyDescAngelType: "1", //活动描述底框倒角 0直角 1倒角

        //剩余次数
        residueNumColor: "#bfbfbf", //剩余次数字体颜色
        residueNumfontSize: 12, //剩余次数字体大小
        residueNumfontWeight: "normal", //剩余次数字体粗细
        residueNumBordercolor: "#383838", //剩余次数底框颜色
        residueNumAngelType: "0", //剩余次数底框倒角 0直角 1倒角

        //盲盒自定义
        BoxImgUrl: "", //盲盒自定义图片
        BoxStyleType: 1, //盲盒自定义类型1系统样式 2自定义
        BoxColor: "#ffffff", //盲盒自定义字体颜色
        BoxfontSize: 14, //盲盒自定义字体大小
        BoxfontWeight: "bold", //盲盒自定义字体粗细
        BoxBordercolor: "#383767", //盲盒自定义底框颜色
        BoxAngelType: "1", //盲盒自定义底框倒角 0直角 1倒角

        //奖品池
        giftPoolColor: "#ffffff", //奖品池字体颜色
        giftPoolfontSize: 16, //奖品池字体大小
        giftPoolfontWeight: "bold", //奖品池字体粗细
        poolTitleColor: "#c0a27b", //标题底框颜色
        poolAngelType: "1", //奖品池底框倒角 0直角 1倒角
        poolTextColor: "#3d3d4e", //奖品池内容底框颜色
        pooltextAngelType: "1", //奖品池内容底框倒角 0直角 1倒角

        //中奖轮播
        prizeCarousel: 1, //中奖轮播 1展示 0隐藏
        prizeColor: "#ffffff", //中奖轮播字体颜色
        prizefontSize: 14, //中奖轮播字体大小
        prizefontWeight: "bold", //中奖轮播字体粗细
        prizeBordercolor: "#c8505c", //中奖轮播底框颜色
        prizeAngelType: "1", //中奖轮播底框倒角 0直角 1倒角

        //我的奖品
        awardColor: "#ffffff", //我的奖品字体颜色
        awardfontSize: 16, //我的奖品字体大小
        awardfontWeight: "bold", //我的奖品字体粗细
        awardTitleColor: "#c0a27b", //我的奖品标题底框颜色
        awardAngelType: "1", //我的奖品底框倒角 0直角 1倒角
        awardTextColor: "#3d3d4e", //我的奖品内容底框颜色
        awardTextAngelType: "1", //奖品池内容底框倒角 0直角 1倒角

        //我的奖品按钮
        awardBtnColor: "#ffffff", //我的奖品按钮字体颜色
        awardfontBtnSize: 14, //我的奖品按钮字体大小
        awardfontBtnWeight: "bold", //我的奖品按钮字体粗细
        awardTitleBtnColor: "#676596", //我的奖品按钮底框颜色
        awardAngelBtnType: "1", //我的奖品按钮底框倒角 0直角 1倒角

        //活动规则标题
        ruleTitleColor: "#ffffff", //活动规则标题字体颜色
        ruleTitlefontSize: 16, //活动规则标题字体大小
        ruleTitlefontWeight: "bold", //活动规则标题字体粗细
        ruleTitlebgColor: "#c0a27b", //活动规则标题底框颜色
        ruleTitleAngelType: "1", //活动规则标题底框倒角 0直角 1倒角

        //活动规则内容
        ruleTextColor: "#ffffff", //活动规则内容字体颜色
        ruleTextfontSize: 12, //活动规则内容字体大小
        ruleTextfontWeight: "bold", //活动规则内容字体粗细
        ruleTextbgColor: "#3d3d4e", //活动规则内容标题底框颜色
        ruleTextAngelType: "1", //活动规则内容底框倒角 0直角 1倒角

        drawtColor: "#ffffff", //悬浮获取抽奖按钮字体颜色
        drawfontSize: 16, //悬浮获取抽奖按钮字体大小
        drawfontWeight: "bold", //悬浮获取抽奖按钮字体粗细
        drawbgColor: "#c8505c", //悬浮获取抽奖按钮标题底框颜色
        drawAngelType: "1", //悬浮获取抽奖按钮底框倒角 0直角 1倒角

        //高级设置
        //中奖实物效果弹窗
        winningPrizeType: 1, //中奖实物效果类型1系统样式 2自定义
        winningPrizeImgUrl: "", //中奖实物效果地址
        winningPrizeColor: "#ffffff",
        //未中奖效果弹窗
        noWinningType: 1, //未中奖实物效果类型1系统样式 2自定义
        noWinningImgUrl: "", //中奖实物效果地址
        //积分展示图
        integralType: 1, //积分展示图效果类型1系统样式 2自定义
        integralImgUrl: "", //积分展示图地址
        integralColor: "#ffffff",
        //优惠券展示图
        couponType: 1, //积分展示图效果类型1系统样式 2自定义
        couponImgUrl: "", //优惠券展示图地址
        couponColor: "#ffffff",
        //分享样式海报图
        posterType: 1, //海报图类型1系统样式 2自定义
        posterImgUrl: "", //海报图地址
        posterText: "惊喜盲盒快来猜，数量有限先到先得", //分享海报文案
      },
      current: 0,
      stepConfig: [
        { title: "1.创建活动", check: false },
        { title: "2.奖品设置", check: false },
        { title: "3.页面装修", check: false },
      ],
      readOnly: false, //判断是否可编辑 禁用
      passModify: true, //判断进行中的活动修改口令及商品数量
      passwordInfo: {}, //口令抽奖信息， 主要获取id用于修改口令抽奖
    };
  },
  created() {
    if (this.$route.query.activityStatus) {
      if (
        // this.$route.query.activityStatus == 0 ||
        // this.$route.query.activityStatus == 2 ||
        // this.$route.query.activityStatus == 3 ||
        this.$route.query.activityStatus != 1
        // this.$route.query.isChoose == 1
      ) {
        this.readOnly = true;
      }

      if (this.$route.query.activityStatus == 2) {
        this.passModify = false;
      } else {
        this.passModify = true;
      }
    } else {
      this.readOnly = false;
      this.passModify = true;
    }

    if (this.$route.query.id) {
      this.getInitData();
    }
  },
  methods: {
    handelBack() {
      this.$router.push("/marketing/lottery");
    },
    handelNext() {
      if (this.current == 0) {
        this.$refs.addActive.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            if (this.formData.participant == 1) {
              if (
                this.formData.benefitsCardIdList.length == 0 &&
                this.formData.labelIdList.length == 0
              ) {
                this.$message.error("请添加权益卡和用户标签选择");
                // num++;
                return;
              }
            }
            if (this.formData.activeType == 3) {
              if (this.formData.conditionalLottery.indexOf("6") > -1) {
                if (this.formData.goodsIdList.length == 0) {
                  this.$message.error("请添加条件抽奖指定活动商品");
                  return;
                }
              }
            }
            const conditionalInfo = [
              {
                sourceType: 1,
                number: this.formData.conditionalData.freeNum,
              },
              {
                sourceType: 2,
                number: this.formData.conditionalData.freeLotteryNum,
              },
              {
                sourceType: 3,
                number: this.formData.conditionalData.integralNum,
                ceiling: this.formData.conditionalData.exchangeNum,
              },
              {
                sourceType: 4,
                number: this.formData.conditionalData.shareNum,
                ceiling: this.formData.conditionalData.sharelimitNum,
              },
              {
                sourceType: 5,
                number: this.formData.conditionalData.friendsNum,
                ceiling: this.formData.conditionalData.limitfriendsNum,
              },
              {
                sourceType: 6,
                number: this.formData.conditionalData.buyNum,
                ceiling: this.formData.conditionalData.limitBuyNum,
              },
              {
                sourceType: 7,
                number: this.formData.conditionalData.cashNum,
                ceiling: this.formData.conditionalData.exchangeCount,
                amount: this.formData.conditionalData.cashCount,
              },
              {
                sourceType: 8,
                number: this.formData.conditionalData.singleNum,
                ceiling: this.formData.conditionalData.singleLimitNum,
                amount: this.formData.conditionalData.singleMoney,
              },
              {
                sourceType: 9,
                number: this.formData.conditionalData.increaseNum,
                ceiling: this.formData.conditionalData.increaseLimitNum,
                amount: this.formData.conditionalData.increaseMoney,
              },
              {
                sourceType: 10,
                number: this.formData.conditionalData.passwordNumber,
                password: this.formData.conditionalData.password,
              },
            ];
            const conditionLotteryList = [];
            conditionalInfo.forEach((l) => {
              this.formData.conditionalLottery.forEach((item) => {
                if (l.sourceType == item) conditionLotteryList.push(l);
              });
            });
            let num = 0;
            conditionLotteryList.forEach((item) => {
              if (
                item.sourceType == 6 ||
                item.sourceType == 8 ||
                item.sourceType == 9
              ) {
                num++;
              }
            });
            if (num >= 2) {
              this.$message.warning(
                "抽奖活动里最多只能有购买指定商品、单笔满抽、单笔递增满抽里面的一种"
              );
              return;
            }

            if (this.formData.conditionalLottery.indexOf("10") > -1) {
              if (!this.formData.conditionalData.password) {
                this.$message.error("口令抽奖口令不能为空");
                return;
              }
              if (!this.formData.conditionalData.passwordNumber) {
                this.$message.error("口令抽奖兑换次数不能为空");
                return;
              }
            }
            this.current++;
            this.$message.success("下一步");
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      } else if (this.current == 1) {
        if (
          this.formData.tableData.length == 0 ||
          this.formData.tableData.length > 15
        ) {
          this.$message.warn("请选择1-15件奖品");
        } else {
          this.current++;
        }
      } else {
        this.current++;
      }
      // this.current++;
    },
    handelPrev() {
      this.current--;
      this.$message.success("上一步");
    },
    handelCommit() {
      const conditionalInfo = [
        {
          sourceType: 1,
          number: this.formData.conditionalData.freeNum,
        },
        {
          sourceType: 2,
          number: this.formData.conditionalData.freeLotteryNum,
        },
        {
          sourceType: 3,
          number: this.formData.conditionalData.integralNum,
          ceiling: this.formData.conditionalData.exchangeNum,
        },
        {
          sourceType: 4,
          number: this.formData.conditionalData.shareNum,
          ceiling: this.formData.conditionalData.sharelimitNum,
        },
        {
          sourceType: 5,
          number: this.formData.conditionalData.friendsNum,
          ceiling: this.formData.conditionalData.limitfriendsNum,
        },
        {
          sourceType: 6,
          number: this.formData.conditionalData.buyNum,
          ceiling: this.formData.conditionalData.limitBuyNum,
        },
        {
          sourceType: 7,
          number: this.formData.conditionalData.cashNum,
          ceiling: this.formData.conditionalData.exchangeCount,
          amount: this.formData.conditionalData.cashCount,
        },
        {
          sourceType: 8,
          number: this.formData.conditionalData.singleNum,
          ceiling: this.formData.conditionalData.singleLimitNum,
          amount: this.formData.conditionalData.singleMoney,
        },
        {
          sourceType: 9,
          number: this.formData.conditionalData.increaseNum,
          ceiling: this.formData.conditionalData.increaseLimitNum,
          amount: this.formData.conditionalData.increaseMoney,
        },
        {
          sourceType: 10,
          number: this.formData.conditionalData.passwordNumber,
          password: this.formData.conditionalData.password,
        },
      ];
      const prizePool = [];
      this.formData.tableData.forEach((item) => {
        const prizeItem = {};
        if (item.prizeType == 1) {
          prizeItem.prizeType = item.prizeType * 1;
          prizeItem.relationId = item.relationId;
          prizeItem.prizeName = item.prizeName;
          prizeItem.amount = item.amount;
          prizeItem.odds = item.odds;
          prizeItem.issueCount = item.issueCount;
        } else if (item.prizeType == 2) {
          prizeItem.prizeType = item.prizeType * 1;
          prizeItem.prizeName = item.prizeName;
          prizeItem.amount = item.amount;
          prizeItem.odds = item.odds;
          prizeItem.issueCount = item.issueCount;
          prizeItem.integralCount = item.integralCount;
        } else if (item.prizeType == 3) {
          prizeItem.prizeType = item.prizeType * 1;
          prizeItem.prizeName = item.prizeName;
          prizeItem.amount = item.amount;
          prizeItem.odds = item.odds;
          prizeItem.issueCount = item.issueCount;
          prizeItem.relationId = item.relationId;
          prizeItem.validDay = item.validDay;
          prizeItem.goodsType = item.goodsType;
        }
        prizePool.push(prizeItem);
      });

      const pageJson = JSON.parse(JSON.stringify(this.formData.pageJson));
      pageJson.boxList = pageJson.boxList.map((item, index) => {
        if (pageJson.BoxNum < index + 1) {
          item = "神秘拆盲盒";
        }
        return item;
      });
      const conditionLotteryList = [];
      conditionalInfo.forEach((l) => {
        this.formData.conditionalLottery.forEach((item) => {
          if (l.sourceType == item) conditionLotteryList.push(l);
        });
      });
      let params = {};
      params = {
        lotteryType: this.$route.query.lotteryType * 1 || 1,
        activityName: this.formData.activeName,
        startDate: this.formData.startDate,
        endDate: this.formData.endDate,
        isRestrictParticipants: this.formData.participant * 1,
        labelIdList: this.formData.labelIdList,
        benefitsCardIdList: this.formData.benefitsCardIdList,
        activityType:
          this.formData.activeType == 1
            ? this.formData.unlimited * 1
            : this.formData.activeType * 1,
        lotteryCount: this.formData.limitedNum * 1,
        conditionLotteryList: conditionLotteryList,
        goodsIdList: this.formData.goodsIdList,
        joinGivingIntegral: this.formData.sendPoints * 1,
        onlyLosingUser: this.formData.notWinning == true ? 1 : 0,
        givingGoodsRemark: this.formData.giftRules,
        unitCountLimit: this.formData.peopleCount,
        isAudit: this.formData.isAudit,
        validDuration: this.formData.validDuration,
        prizePoolList: prizePool,
        pageMsJson: JSON.stringify(pageJson),
        // pageMsJson: pageJson,
      };
      if (params.isRestrictParticipants == 0) {
        delete params.labelIdList;
        delete params.benefitsCardIdList;
      }
      if (params.activityType == 1) {
        delete params.lotteryCount;
        delete params.conditionLotteryList;
        delete params.goodsIdList;
      } else if (params.activityType == 1) {
        delete params.conditionLotteryList;
        delete params.goodsIdList;
      }
      if (params.conditionLotteryList) {
        let num = 0;
        params.conditionLotteryList.forEach((item) => {
          if (item.sourceType == 6) {
            num++;
          }
        });
        if (!num > 0) {
          delete params.goodsIdList;
        }
      }
      if (this.formData.probabilitySetting == 1) {
        delete params.unitCountLimit;
        params.prizePoolList.forEach((item) => {
          delete item.issueCount;
        });
      }
      if (this.formData.isAudit == 0) {
        delete params.validDuration;
      }
      console.log(params);
      if (this.$route.query.type == 2) {
        params.id = this.$route.query.id;
        this.createActive(params);
      } else {
        if (this.$route.query.id) {
          params.id = this.$route.query.id;
          this.updateActive(params);
        } else {
          this.createActive(params);
        }
      }

      // this.$router.push({
      //   name: "MarketingLottery",
      // });
    },
    //添加活动
    async createActive(params) {
      let res = await this.$post(
        "goldenhome/gh/lottery/admin_/lottery/activity/add",
        params
      );
      if (res && res.returnCode == 1000) {
        // console.log(res);
        if (this.$route.query.type == 2) {
          this.$message.success("复制成功");
        } else {
          this.$message.success("创建成功");
        }
        this.$router.push({
          name: "MarketingLottery",
        });
      }
    },
    //编辑活动
    async updateActive(params) {
      let res = await this.$post(
        "goldenhome/gh/lottery/admin_/lottery/activity/update",
        params
      );
      if (res && res.returnCode == 1000) {
        // console.log(res);
        this.$message.success("保存成功");
        this.$router.push({
          name: "MarketingLottery",
        });
      }
    },
    //初始化数据
    async getInitData() {
      let res = await this.$get(
        "goldenhome/gh/lottery/admin_/lottery/activity/id",
        {
          id: this.$route.query.id,
        }
      );
      if (res && res.returnCode == 1000) {
        if (res.dataInfo) {
          let data = res.dataInfo;
          let conditionalLottery = [];
          let conditionalData = {
            product: "1",
          };
          if (data.activityType == 3) {
            data.conditionLotteryList.forEach((item) => {
              conditionalLottery.push(item.sourceType + "");
              if (item.sourceType == 1) {
                conditionalData.freeNum = item.number || 1;
              } else if (item.sourceType == 2) {
                conditionalData.freeLotteryNum = item.number || 1;
              } else if (item.sourceType == 3) {
                conditionalData.integralNum = item.number || 1;
                conditionalData.exchangeNum = item.ceiling || 1;
              } else if (item.sourceType == 4) {
                conditionalData.shareNum = item.number || 1;
                conditionalData.sharelimitNum = item.ceiling || 1;
              } else if (item.sourceType == 5) {
                conditionalData.friendsNum = item.number || 1;
                conditionalData.limitfriendsNum = item.ceiling || 1;
              } else if (item.sourceType == 6) {
                conditionalData.buyNum = item.number || 1;
                conditionalData.limitBuyNum = item.ceiling || 1;
              } else if (item.sourceType == 7) {
                conditionalData.cashNum = item.number || 1;
                conditionalData.exchangeCount = item.ceiling || 1;
                conditionalData.cashCount = item.amount || 1;
              } else if (item.sourceType == 8) {
                conditionalData.singleNum = item.number || 1;
                conditionalData.singleLimitNum = item.ceiling || 1;
                conditionalData.singleMoney = item.amount || 1;
              } else if (item.sourceType == 9) {
                conditionalData.increaseNum = item.number || 1;
                conditionalData.increaseLimitNum = item.ceiling || 1;
                conditionalData.increaseMoney = item.amount || 1;
              } else if (item.sourceType == 10) {
                conditionalData.password = item.remark || "";
                conditionalData.passwordNumber = item.number || 1;
                this.passwordInfo = item;
              }
            });
          } else {
            conditionalData = {
              integralNum: 1,
              exchangeNum: 1,
              freeNum: 1,
              priceNum: 1,
              orderNum: 1,
              shareNum: 1,
              friendsNum: 1,
              freeLotteryNum: 1,
              buyNum: 1,
              cashNum: 1,
              cashCount: 1,
              product: "1",
              exchangeCount: 1,
              sharelimitNum: 1,
              limitfriendsNum: 1,
              limitBuyNum: 1,
              singleNum: 1,
              singleMoney: 1,
              singleLimitNum: 1,
              increaseNum: 1,
              increaseMoney: 1,
              increaseLimitNum: 1,
              password: "",
              passwordNumber: 1,
            };
          }
          let probabilitySetting = "1";
          if (data.unitCountLimit) {
            probabilitySetting = "2";
          } else {
            probabilitySetting = "1";
          }
          //初始化单位人次颁发次数
          data.prizePoolList.forEach((item) => {
            if (!item.issueCount) {
              item.issueCount = 1;
            }
          });
          //装修样式兼容旧数据
          let pageMsJson = this.isJSON(data.pageMsJson)
            ? JSON.parse(data.pageMsJson)
            : this.pageJson;
          if (!("myPrizeBtnShow" in pageMsJson)) {
            pageMsJson.myPrizeBtnShow = 1;
            pageMsJson.myPrizeBtnName = "已发放，查看";
            pageMsJson.awardBtnColor = "#ffffff";
            pageMsJson.awardfontBtnSize = 14;
            pageMsJson.awardfontBtnWeight = 'bold';
            pageMsJson.awardTitleBtnColor = "#676596";
            pageMsJson.awardAngelBtnType = "1";
          }
          this.formData = {
            activeName: data.activityName,
            activeTime: data.startDate + "-" + data.endDate,
            startDate: data.startDate,
            endDate: data.endDate,
            participant: data.isRestrictParticipants + "",
            benefitsCardIdList: data.benefitsCardIdList || [],
            labelIdList: data.labelIdList || [],
            goodsIdList: data.goodsIdList || [],
            activeType: data.activityType == 3 ? "3" : "1",
            unlimited: data.activityType == 2 ? "2" : "1",
            limitedNum: data.lotteryCount || 1,
            conditionalLottery: conditionalLottery,
            conditionalData: conditionalData,
            //奖品设置
            tableData: data.prizePoolList || [],
            probabilitySetting: probabilitySetting,
            isAudit: data.isAudit + "" || "0",
            validDuration: data.validDuration || 1,
            peopleCount: data.unitCountLimit || 100,
            sendPoints: data.joinGivingIntegral || 0,
            notWinning: data.onlyLosingUser == 1 ? true : false,
            giftRules: data.givingGoodsRemark,
            pageJson: pageMsJson,
          };
          //复制活动
          if (this.$route.query.type == 2) {
            this.formData.activeName = this.formData.activeName + "副本";
            this.formData.activeTime = "";
            this.formData.startDate = "";
            this.formData.endDate = "";
            this.formData.goodsIdList = [];
            this.formData.tableData.forEach((item) => {
              item.remainingStock =
                item.remainingStock > item.amount
                  ? item.remainingStock - item.amount
                  : item.remainingStock;
            });
            this.formData.tableData.forEach((item) => {
              item.chooseAmount = 0;
              if (item.remainingStock) {
                if (item.amount > item.remainingStock) {
                  item.amount = item.remainingStock;
                }
              }
            });
          }
        }
      }
    },
    //判断Json字符串是不是对象格式
    isJSON(str) {
      if (typeof str == "string") {
        try {
          var obj = JSON.parse(str);
          if (typeof obj == "object" && obj) {
            return true;
          } else {
            return false;
          }
        } catch (e) {
          console.log("error：" + str + "!!!" + e);
          return false;
        }
      }
    },
  },
};
</script>

<style scoped lang="less">
.step-progress {
  .step-container {
    margin: auto;
    display: flex;
    width: 80%;
    .step-item {
      flex: 1;
      height: 40px;
      line-height: 40px;
      background: #aaaaaa;
      position: relative;
      margin-right: 25px;
      text-align: center;
      color: #ffffff;

      &.active {
        background: #1890ff;

        .step-left {
          border-bottom-color: #1890ff;
          border-top-color: #1890ff;
        }

        .step-right {
          border-left-color: #1890ff;
        }
      }
      &:last-child {
        margin-right: 0;
      }
      .text {
        font-size: 16px;
      }
      .step-icon {
        width: 0;
        height: 0;
        border: 20px solid;
        position: absolute;
        top: 0;
      }

      .step-left {
        border-left-color: transparent;
        border-bottom-color: #aaaaaa;
        border-right-color: transparent;
        border-top-color: #aaaaaa;
        left: -20px;
      }

      .step-right {
        border-left-color: #aaaaaa;
        border-bottom-color: transparent;
        border-right-color: transparent;
        border-top-color: transparent;
        right: -40px;
      }
    }
  }
  .step-body {
    position: relative;
  }
  .steps-action {
    margin-top: 15px;
    text-align: center;
    .btn {
      margin: 0 10px;
    }
  }
}
</style>
